
package com.dps.omc.service.impl;
import com.dps.omc.model.Artifact;
import com.dps.omc.model.Job;
import com.dps.omc.service.IArtifactService;
import com.dps.common.utils.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dps.common.service.impl.AbstractPageService;
import com.dps.omc.dao.IJobArtifactDAO;
import com.dps.omc.model.JobArtifact;
import com.dps.omc.service.IJobArtifactService;

import java.util.List;

@SuppressWarnings("unchecked")
@Service("JobArtifactServiceImpl")

public class JobArtifactServiceImpl extends AbstractPageService<IJobArtifactDAO,JobArtifact> implements IJobArtifactService {

	@Autowired
	private IJobArtifactDAO jobArtifactDAO;
	@Autowired
	private IArtifactService artifactService;
	@Override
	public boolean getEnableDataPerm() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public IJobArtifactDAO getDao() {
		return jobArtifactDAO;
	}

	@Override
	public void create(Job job, List<JobArtifact> jobArtifacts) {
		this.deleteByProperty("jobId",job.getId());
		int seq = 1;
		for(JobArtifact jobArtifact:jobArtifacts)
		{
			Artifact artifact = artifactService.fetch(jobArtifact.getArtifactId());
			jobArtifact.setId(IdGenerator.createNewId());
			jobArtifact.setJobId(job.getId());
			jobArtifact.setArtifactName(artifact.getName());
			jobArtifact.setArtifactPath(artifact.getPath());
			jobArtifact.setArtifactSize(artifact.getSizeLength());
			jobArtifact.setWarnFlag(artifact.getWarnFlag());
			this.insert(jobArtifact);
			seq++;
		}
	}
}
